﻿using System;
using System.Drawing;

namespace TrafficWatcher.Views.Helpers.TimeVisualizers
{
    class CircleVisualizer : ITimeVisualizer
    {
        private const int ThirtyTwoPixelsForIcon = 32;

        public Bitmap GenerateImage(TimeSpan travelTime)
        {
            var backgroundColor = Color.Yellow;

            if (travelTime.Hours == 0)
                backgroundColor = Color.Green;
            else if (travelTime.Hours == 1)
                backgroundColor = Color.Blue;

            var bitmap = new Bitmap(ThirtyTwoPixelsForIcon, ThirtyTwoPixelsForIcon);

            using (var g = Graphics.FromImage(bitmap))
            using (var hoursBrush = new SolidBrush(backgroundColor))
            using (var minuntesBrush = new SolidBrush(Color.Red))
            {
                var r = new Rectangle(0, 0, ThirtyTwoPixelsForIcon, ThirtyTwoPixelsForIcon);
                g.FillEllipse(hoursBrush, r);
                g.FillPie(minuntesBrush, r, 270, travelTime.Minutes * 6); // angle = minutes * 360 degree / 60 minutes
            }

            return bitmap;
        }

        public TimeSpan MaxDuration { get { return TimeSpan.FromHours(3); } }
    }
}